<?php

namespace app\admin\model\finance;

use think\Model;


class Abnormal extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'order_job_type_text',
        'total_time_text',
        'user_first_time_text',
        'user_second_time_text',
        'company_first_time_text',
        'company_second_time_text',
        'is_abnormal_text',
        'is_renewal_text',
        'status_text'
    ];
    

    
    public function getOrderJobTypeList()
    {
        return ['1' => __('Order_job_type 1'), '2' => __('Order_job_type 2'), '3' => __('Order_job_type 3'), '4' => __('Order_job_type 4')];
    }

    public function getIsAbnormalList()
    {
        return ['1' => __('Is_abnormal 1'), '2' => __('Is_abnormal 2')];
    }

    public function getIsRenewalList()
    {
        return ['1' => __('Is_renewal 1'), '2' => __('Is_renewal 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6')];
    }


    public function getOrderJobTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_job_type']) ? $data['order_job_type'] : '');
        $list = $this->getOrderJobTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTotalTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['total_time']) ? $data['total_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUserFirstTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['user_first_time']) ? $data['user_first_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUserSecondTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['user_second_time']) ? $data['user_second_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCompanyFirstTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['company_first_time']) ? $data['company_first_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCompanySecondTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['company_second_time']) ? $data['company_second_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsAbnormalTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_abnormal']) ? $data['is_abnormal'] : '');
        $list = $this->getIsAbnormalList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsRenewalTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_renewal']) ? $data['is_renewal'] : '');
        $list = $this->getIsRenewalList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setTotalTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUserFirstTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUserSecondTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCompanyFirstTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCompanySecondTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function hotel()
    {
        return $this->belongsTo('app\admin\model\Hotel', 'hotel_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
